(no optimal sub-structure is actually no DP)F[I][J], indicating the number of programs transmitted to the J-man in the first time. By the conditions in question, a person can only take the ball from the left and right side, so obviously the recursive equation f[i][j]=f[i-1][j-1]+f[i-1][j+1], because the station into a ring, so the number 1th and the last special treatment.Data size does not require scrolling arrayPaste Code1#include 2#include 3 intpu[301][301]={{0}};4 intMain () {5 intM,n;6
(int (i) = (x);(i) #defineMax (x, y) > (y)? (x):(y)intdp[Wuyi][Wuyi][Wuyi][Wuyi],lk[Wuyi][Wuyi];intMain () {intM,n; scanf ("%d%d",m,N); F (i,1, M) F (J,1, N) scanf ("%d",Lk[i][j]); Memset (DP,0,sizeof(DP)); F (i,1, M) F (J,1, N) F (II,1, m) F (JJ,1, N) {DP[I][J][II][JJ]=max (dp[i][j][ii][jj],dp[i-1][j][ii-1][JJ]); DP[I][J][II][JJ]=max (dp[i][j][ii][jj],dp[i-1][j][ii][jj-1]); DP[I][J][II][JJ]=max (dp[i][j][ii][jj],dp[i][j-1][ii][jj-1]); DP[I][J][II][JJ]=max (dp[i][j][ii][jj],dp[i][j-1][ii-1][JJ]
interval modification operation is split into insert/delete, and each query action is sorted by the horizontal axis x ascending.A one-dimensional array is used to record the y-axis of "current horizontal", and all operations are scanned from left to right, and the change is done in a differential way (differential on the Time dimension) to record the answer.↑ The one-dimensional array can be optimized with a tree-like array, and the scan operation can be optimized with a split-rule method (the
by dict [key] = default.
Update (dict2): Add the dictionary dict2 key-value pairs to the current dictionary.
Values (): Returns a list containing all values in the dictionary.
The following is a simulationUser LogonThe data system is used as an example to describe how to use the dictionary.
#!/usr/bin/env python db = {} def newuser(): prompt = 'register: ' while True: name = raw_input(prompt) if db.has_key(name): prompt = 'name taken, try another: ' continue else: break pwd = raw_input('passw
] '%choice if choice not in ' RLQ ': print ' invalid option, try again ' else : chosen = true if choice = = ' R ': NewUser () elif choice = = ' L ': olduser () Else:done = true if __name__ = = ' __main__ ': Sho Wmenu ()the third line of the script initializes an emptyDBDictionary, section9Line throughHas_key ()determine the newly registered user name (the dictionary'sKey) is present, section theline through square brackets[]add a password to a user na
Contact Us
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.